package wxk.interview.method;

/**
 * @author wangxuekai
 * @version 2.2
 * @Date 2017/3/23.
 * @since 2.2
 */
public class CastMethod {

    static class  A {
        String name ;

        public A() {
        }

        public A(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return "A{" + "name='" + name + '\'' +
                    '}';
        }
    }

    static class B extends A{
        Integer age;

        public B(Integer age) {
            this.age = age;
        }

        public B(String name, Integer age) {
            super(name);
            this.age = age;
        }

        @Override
        public String toString() {
            return "B{" + "age=" + age +
                    '}';
        }
    }

    public static void main(String[] args){
        A a = new B("张三",12);

        B b = B.class.cast(a);

        System.out.println(a);
        System.out.println(b+","+b.getClass().getName());

        int i = Integer.class.cast("123");

        System.out.println(i);
    }
}
